import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/business/saleOrder/list',
  save = '/business/saleOrder/add',
  edit = '/business/saleOrder/edit',
  deleteOne = '/business/saleOrder/delete',
  deleteBatch = '/business/saleOrder/deleteBatch',
  importExcel = '/business/saleOrder/importExcel',
  exportXls = '/business/saleOrder/exportXls',
  busSaleOrderItemList = '/business/saleOrder/queryBusSaleOrderItemByMainId',
  currencyList = '/base/currency/list',
  customerList = '/base/customer/list',
  organizationList = '/sys/businessOrganization/list',
  paymentConditionList = '/base/paymentCondition/list',
  materialList = '/base/material/list',
  unitList = '/base/unit/list',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询子表数据
 * @param params
 */
export const busSaleOrderItemList = Api.busSaleOrderItemList;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });
/**
 * 币种接口
 * @param params
 */
export const currencyList = (params) =>
  defHttp.get({ url: Api.currencyList, params });
/**
* 客户接口
* @param params
*/
export const customerList = (params) =>
  defHttp.get({ url: Api.customerList, params });
/**
* 组织接口
* @param params
*/
export const organizationList = (params) =>
  defHttp.get({ url: Api.organizationList, params });
/**
* 条件接口
* @param params
*/
export const paymentConditionList = (params) =>
  defHttp.get({ url: Api.paymentConditionList, params });
/**
* 料品接口
* @param params
*/
export const materialList = (params) =>
  defHttp.get({ url: Api.materialList, params });
/**
* 单位接口
* @param params
*/
export const unitList = (params) =>
  defHttp.get({ url: Api.unitList, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
}